package com.ruoyi.security.convert;

import com.ruoyi.security.domain.Security;
import com.ruoyi.security.dto.SecurityDto;
import com.ruoyi.security.enums.SecurityTypeEnum;
import com.ruoyi.security.response.SecurityResponse;
import com.ruoyi.security.vo.SecurityVo;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;

import java.util.List;

import static org.mapstruct.factory.Mappers.getMapper;

/**
 * @author yeoman
 * @date 2025/5/4 11:19
 * @description
 */
@Mapper(imports = SecurityTypeEnum.class)
public interface SecurityConvert {

    SecurityConvert INSTANCE = getMapper(SecurityConvert.class);

    List<Security> toSecurityList(List<SecurityResponse> list);

    @Mappings({
            @Mapping(source = "trade",target = "latestPrice"),
            @Mapping(source = "pricechange",target = "riseFallAmount"),
            @Mapping(source = "changepercent",target = "riseFallAmountPercentage"),
            @Mapping(source = "buy",target = "buyPrice"),
            @Mapping(source = "sell",target = "sellPrice"),
            @Mapping(source = "settlement",target = "previousClosePrice"),
            @Mapping(source = "open",target = "openPrice"),
            @Mapping(source = "high",target = "highestPrice"),
            @Mapping(source = "low",target = "lowestPrice"),
            @Mapping(source = "amount",target = "turnover")
    })
    Security toSecurity(SecurityResponse response);

    List<SecurityVo> toSecurityVoList(List<Security> list);

    @Mappings({
            @Mapping(target = "securityTypeName", expression = "java(SecurityTypeEnum.getByKey(security.getType()).getName())"),
            @Mapping(target = "minTradeQuantity", expression = "java(SecurityTypeEnum.getByKey(security.getType()).getMinTradeQuantity())"),
            @Mapping(target = "tradeUnit", expression = "java(SecurityTypeEnum.getByKey(security.getType()).getTradeUnit())")
    })
    SecurityVo toSecurityVo(Security security);

}
